//此文件是用于读取数据
//读取数据的地方： 1.数据库（mysql） redis
const dbConnect = require("../utils/dbConnect");
// const { errorModel } = require("../utils/resModel");
// const checkData=require("../utils/checkData");


const getUserInfo = async (data) => {
    let _sql = `SELECT phone,is_appointment,name,qrcode,sessions_id,sessions_time FROM user WHERE name="${data.name}"AND phone="${data.phone}" AND idcard="${data.idcard}"`;
   
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

const register = async (data) => {
    let _sql = `INSERT INTO user (name,phone,idcard,token)VALUES("${data.name}","${data.phone}","${data.idcard}","${data.token}")`;
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

const updateToken=async(phone,token)=>{
    let _sql=`UPDATE user SET token = "${token}" WHERE phone = ${phone}`
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

const tokenToInfo= async (data)=>{
    let _sql=`SELECT * FROM user WHERE token='${data.token}'`;
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}
module.exports = { getUserInfo, register,updateToken,tokenToInfo };